
specHelper=new (function(){
this.TAOKONG=1;
this.TUOYUAN=2;
this.PAODAO=3;
this.PAODAOKONG=4;
this.FANGKUAI=5;
this.YUANZHU=6;


this.NAME_TAOKONG="套孔";
this.NAME_DAKONG="打孔";
this.NAME_QIANDAOMO="前道磨加工";
this.NAME_MOJIAGONG="磨加工";


this.att=[];
this.before="";
this.setSpec=function(A){};
this.yuanzhu=function(A,B){
this.att=[];
	this.att[0]=A;
	this.att[1]=B;
	this.type=this.YUANZHU;
	
}
this.taokong=function(A,B,C){
	this.att=[];
	this.att[0]=A;
	this.att[1]=B;
	this.att[2]=C;
	this.type=this.TAOKONG;
};
this.tuoyuan=function(A,B,C,D){
	this.att=[];
	this.att[0]=A;
	this.att[1]=B;
	this.att[2]=C;
	this.att[3]=D;
	this.type=this.TUOYUAN;
};
this.paodao=function(A,B,C,D,E,F,G){
	this.att=[];
	this.att[0]=A;
	this.att[1]=B;
	this.att[2]=C;
	this.att[3]=D;
	this.att[4]=E;
	this.att[5]=F;
	this.att[6]=G;
	this.type=this.PAODAO;
};
this.paodaokong=function(A,B,C,D,E){
	this.att=[];
	this.att[0]=A;
	this.att[1]=B;
	this.att[2]=C;
	this.att[3]=D;
	this.att[4]=E;
	this.type=this.PAODAOKONG;
};
this.fangkuai=function(A,B,C){
	this.att=[];
	this.att[0]=A;
	this.att[1]=B;
	this.att[2]=C;
	this.type=this.FANGKUAI;
};
this.isFangKuai=function(A){
	this.parser(A,0);
	return this.type==this.FANGKUAI;
};
this.isTuoYuan=function(A,B,C,D){
	this.parser(A,0);
	return this.type==this.TUOYUAN;
};
this.isTaoKong=function(A){
	this.parser(A,0);
	return this.type==this.TAOKONG;
};
this.isPaoDao=function(A){
	this.parser(A,0);
	return this.type==this.PAODAO;
};
this.isYuanZhu=function(A){
	this.parser(A,0);
	return this.type==this.YUANZHU;
};
this.isPaoDaoKong=function(A){
	this.parser(A,0);
	logger.debug("type:"+this.type);
	return this.type==this.PAODAOKONG;
};

this.MoJiaGong=function(A){
	if(this.type==this.FANGKUAI)//方块磨成R角
	{
		return this.att[0]+"*"+this.att[1]+"*"+this.att[2]+"*R"+parseFloat(this.att[1]/2);
	}
	else if(this.type==this.TUOYUAN)//椭圆磨成R角
	{
		return this.before;
	}
	return false;
}
this.QianDaoMo=function(A){
	return this.before;
}
this.TaoKong=function(A){
	if(this.type==this.YUANZHU)//圆柱搞成套孔
	{
		var t=A.split("*")[1];
		logger.debug("TaoKong Process");
		return "$"+this.att[0]+"*"+t+"*"+this.att[1];
	}
	return false;
}
this.DaKong=function(A){
	if(this.type==this.YUANZHU)//圆柱搞成打孔
	{
		var t=A.split("*")[1];
		return "$"+this.att[0]+"*"+t+"*"+this.att[1];
	}
	return false;
}
this.getNextSpec=function(A,B,C)
{
	this.parser(A);
	return this.getSpecByName(B,C);
}
this.getSpecByName=function(A,B){
	if(A==this.NAME_MOJIAGONG)
		return this.MoJiaGong(B);
	else if(A==this.NAME_DAKONG)
		return this.DaKong(B);
	else if(A==this.NAME_QIANDAOMO)
		return this.QianDaoMo(B);
	else if(A==this.NAME_TAOKONG)
		return this.TaoKong(B);
	else
		return false;
}
this.type=0;
this.getType=function(A){
	this.parser(A);
	switch(this.type)
	{
		case this.TAOKONG:
			return "taokong";
		case this.YUANZHU:
			return "yuanzhu";
		case this.FANGKUAI:
			return "fangkuai";
		case this.TUOYUAN:
			return "tuoyuan";
		case this.PAODAO:
			return "paodao";
		case this.PAODAOKONG:
			return "paodaokong";
		default:
			return "";
	}
}
this.parser=function(A,C){
	if(!A)
		return ;
	this.before=A;
	var B=A.split("*");
	if(B.length==3)
	{
		if(B[0].substring(0,1)=='$')
			C==0?this.type=this.TAOKONG:this.taokong(B[0].substring(1),B[1].substring(1),B[2]);
		else
			C==0?this.type=this.FANGKUAI:this.fangkuai(B[0],B[1],B[2]);
	}
	else if(B.length==2)
	{
		C==0?this.type=this.YUANZHU:this.yuanzhu(B[0].substring(1),B[1]);
	}
	else if(B.length==4)
	{
		if(B[3].substring(0,1)=='$')
		{
			logger.debug("is paodaokong");
			C==0?this.type=this.PAODAOKONG:this.paodaokong(B[0],B[1],B[2],parseFloat(B[1]/2).toFixed(3),B[4].substring(1));
		}
		else
		{
			logger.debug("is tuoyuan");
			C==0?this.type=this.TUOYUAN:this.tuoyuan(B[0],B[1],B[2],B[3].substring(1));
		}
	}
	else if(B.length==5)
	{
		C==0?this.type=this.PAODAOKONG:this.paodaokong(B[0],B[1],B[2],B[3].substring(1),B[4].substring(1));
	}
	else if(B.length==7)
	{
		logger.debug("is paodao:");
		C==0?this.type=this.PAODAO:this.paodao(B[0],B[1],B[2],B[3].substring(1),B[4].substring(1),B[5],B[6]);
	}

};
});
logger.debug(specHelper.getType("1*2*3")=="fangkuai");
logger.debug(specHelper.getType("$1*2")=="yuanzhu");
logger.debug(specHelper.getType("$1*$3*2")=="taokong");
logger.debug(specHelper.getType("1*2*3*R2")=="tuoyuan");
logger.debug(specHelper.getType("1*2*3*R2*$1")=="paodaokong");
logger.debug(specHelper.getType("1*1*1*R1*1*1*R1")=="paodao");
/*logger.debug("start to debug");
logger.debug(specHelper.getNextSpec("$10*30","套孔","$10*$2*20")=="$10*$2*30");
logger.debug(specHelper.getNextSpec("$10*30","打孔","$10*$2*20")=="$10*$2*30");
logger.debug(specHelper.getNextSpec("$10*$2*20","前道磨加工","$10*$2*20")=="$10*$2*20");
logger.debug(specHelper.getNextSpec("10*2*20","前道磨加工","10*2*20")=="10*2*20");
logger.debug(specHelper.getNextSpec("10*20*20","打孔","10*20*10*R10")=="10*20*20*R10");
logger.debug(specHelper.getNextSpec("10*20*20","磨加工","10*20*10*R10*5*5*R2.5")=="10*20*20*R10");
logger.debug(specHelper.getNextSpec("10*20*20","磨加工","10*20*10*R10*$2")=="10*20*20*R10");
logger.debug(specHelper.getNextSpec("10*20*20*R10","前道磨加工","10*20*5*R10")=="10*20*20*R10");*/